﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace App10.Models
{
    public class Post : BindableBase
    {
        public Post()
        {
            var comments = Enumerable.Range(1, 10)
                .Select(i => new Comment
                {
                    Author = "Author " + i.ToString(),
                    Text = "The quick brown fox jumps over the lazy dog."
                });
            foreach (var item in comments)
                this.Comments.Add(item);
        }

        string _Title = default(string);
        public string Title { get { return _Title; } set { SetProperty(ref _Title, value); } }

        string _Text = default(string);
        public string Text { get { return _Text; } set { SetProperty(ref _Text, value); } }

        DateTime _Date = default(DateTime);
        public DateTime Date { get { return _Date; } set { SetProperty(ref _Date, value); } }

        ObservableCollection<Comment> _Comments = new ObservableCollection<Comment>();
        public ObservableCollection<Comment> Comments { get { return _Comments; } }
    }

    public abstract class BindableBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void SetProperty<T>(ref T storage, T value, [System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (!object.Equals(storage, value))
            {
                storage = value;
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        protected void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] String propertyName = null)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

    }

}
